<template>
  <div class="depositslip-edit">
    <el-dialog v-bind="$attrs" :title="state.dialogTitle" v-model="state.modalVisible" :before-close="cancelDialog"
      :append-to-body="true" :destroy-on-close="true" :close-on-click-modal="false" :close-on-press-escape="false"
      :lock-scroll="false" class="depositslip-dialog" draggable>
      <el-form ref="depositslipRef" :model="state.form" :rules="state.rules" label-position="top">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="关联代理商id" prop="depositsagentsid">
              <el-input v-model="state.form.depositsagentsid" placeholder="关联代理商id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联客户id" prop="depositsaccountid">
              <el-input v-model="state.form.depositsaccountid" placeholder="关联客户id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联产品id" prop="depositsproductid">
              <el-input v-model="state.form.depositsproductid" placeholder="关联产品id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单类型(微信,转账)" prop="depositslipype">
              <el-input v-model="state.form.depositslipype" placeholder="付款单类型(微信,转账)" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款银行名称" prop="depositslipyhmc">
              <el-input v-model="state.form.depositslipyhmc" placeholder="付款银行名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款金额" prop="depositslipprice">
              <el-input v-model="state.form.depositslipprice" placeholder="付款金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款账号" prop="depositslipfkzh">
              <el-input v-model="state.form.depositslipfkzh" placeholder="付款账号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际入账金额" prop="depositsliprzprice">
              <el-input v-model="state.form.depositsliprzprice" placeholder="实际入账金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付状态" prop="depositslippaystatus">
              <el-input v-model="state.form.depositslippaystatus" placeholder="支付状态" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付结果返回时间" prop="depositslipreturndate">
              <el-input v-model="state.form.depositslipreturndate" placeholder="支付结果返回时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款流水号" prop="depositslippaylsh">
              <el-input v-model="state.form.depositslippaylsh" placeholder="付款流水号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款时间" prop="depositslipfkdate">
              <el-input v-model="state.form.depositslipfkdate" placeholder="付款时间" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="付款单创建时间" prop="depositslipcreatedate">
              <el-input v-model="state.form.depositslipcreatedate" placeholder="付款单创建时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单创建人" prop="depositslipcreateuser">
              <el-input v-model="state.form.depositslipcreateuser" placeholder="付款单创建人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单审核人" prop="depositslipshr">
              <el-input v-model="state.form.depositslipshr" placeholder="付款单审核人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单审核状态" prop="depositslipshstatus">
              <el-input v-model="state.form.depositslipshstatus" placeholder="付款单审核状态" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单审核时间" prop="depositslipshdate">
              <el-input v-model="state.form.depositslipshdate" placeholder="付款单审核时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单审核备注" prop="depositslipshbz">
              <el-input v-model="state.form.depositslipshbz" placeholder="付款单审核备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单最后更新时间" prop="depositslipupdate">
              <el-input v-model="state.form.depositslipupdate" placeholder="付款单最后更新时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款单最后更新人" prop="depositslipupuser">
              <el-input v-model="state.form.depositslipupuser" placeholder="付款单最后更新人" />
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitDialog">确 定</el-button>
          <el-button @click="cancelDialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import useDepositslipManageManageStore from '@store/modules/depositslipManage'
import { filterObject } from '@/utils/index'
import { nextTick } from 'vue';

const depositslipManageStore = useDepositslipManageManageStore()
const { proxy } = getCurrentInstance()
const depositslipRef = ref(null)

const state = reactive({
  modalVisible: false,
  dialogTitle: '',
  editView: {},
  form: {
    depositslipid: '',
    depositsagentsid: '',
    depositsaccountid: '',
    depositsproductid: '',
    depositslipype: '',
    depositslipyhmc: '',
    depositslipprice: '',
    depositslipfkzh: '',
    depositsliprzprice: '',
    depositslippaystatus: '',
    depositslipreturndate: '',
    depositslippaylsh: '',
    depositslipfkdate: '',
    // depositslipcreatedate: '',
    // depositslipcreateuser: '',
    // depositslipshr: '',
    // depositslipshstatus: '',
    // depositslipshdate: '',
    // depositslipshbz: '',
    // depositslipupdate: '',
    // depositslipupuser: '',
  },
  rules: {
    // account: [{ required: true, message: '账号不能为空', trigger: 'blur' }],
    // username: [{ required: true, message: '姓名/昵称不能为空', trigger: 'blur' }],
    // userworkgroup1: [{ required: true, message: '关联公司不能为空', trigger: 'blur' }],
    // userworkgroup2: [{ required: true, message: '关联部门不能为空', trigger: 'blur' }],
  },
})

const emits = defineEmits(['refresh'])

const getDataView = (depositslipid) => {
  nextTick(async () => {
    const result = await depositslipManageStore.view({ "depositslipid.Value": depositslipid })
    state.editView = result
    state.form = filterObject(result, Object.keys(state.form))
  })
}

const submitDialog = () => {
  depositslipRef.value.validate(async (valid) => {
    if (valid) {
      if (Object.keys(state.editView).length) {
        state.form.depositslipid = state.editView.depositslipid
        await depositslipManageStore.up(state.form)
        proxy.$modal.msgSuccess('修改成功！')
      } else {
        await depositslipManageStore.add(state.form)
        proxy.$modal.msgSuccess('新增成功！')
      }
      state.editView = {}
      depositslipRef.value.resetFields()
      emits('refresh')
      state.modalVisible = false
    }
  })
}

const cancelDialog = () => {
  state.editView = {}
  depositslipRef.value.resetFields()
  state.modalVisible = false
}

const openDialog = async (data = {}) => {
  if (Object.keys(data).length) await getDataView(data.depositslipid)
  state.modalVisible = true
  state.dialogTitle = Object.keys(data).length ? `编辑【${data.depositslipid}】` : '新增'
}

defineExpose({
  openDialog
})
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
